Skip to content

Conversation

aleksanderkatan
Copy link
Contributor

@aleksanderkatan aleksanderkatan commented Sep 29, 2025

Numbers exceeding 2**63 are now automatically inferred as abstractFloat, since it could not fit in an abstractInt anyway.
Now the following does not warn, and the cast is unnecessary.
const FLT_MAX = f32(3.40282346e38);

You could argue that we should cast all numbers exceeding safe integers (~2**53) to floats, and that might be correct. Can you help me decide?

Copy link

github-actions bot commented Sep 29, 2025

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@c7f60c082807aad8b12ddc55ba96ec2250e0a424
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@c7f60c082807aad8b12ddc55ba96ec2250e0a424
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@c7f60c082807aad8b12ddc55ba96ec2250e0a424

benchmark
view benchmark

commit
view commit

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes big integer handling for floating-point literals in the TGSL type system. The fix ensures that very large numeric literals (beyond 2^63) are treated as abstract floats rather than integers, eliminating the need for explicit f32 casts.

  • Added a check in numericLiteralToSnippet to handle values exceeding 2^63 as abstract floats
  • Removed unnecessary f32 casts from floating-point constants like FLT_MAX

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/typegpu/src/tgsl/generationHelpers.ts Added logic to treat large numeric literals as abstract floats
packages/typegpu-color/src/oklab.ts Removed unnecessary f32 cast from FLT_MAX constant
packages/typegpu/tests/examples/individual/oklab.test.ts Updated test expectation to match new FLT_MAX format

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@aleksanderkatan aleksanderkatan marked this pull request as ready for review September 30, 2025 09:57
}

export function numericLiteralToSnippet(value: number): Snippet {
if (Math.abs(value) > 2 ** 63) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure about $2^{63}$ imo limit should be $2^{53}$.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my bad $2^{63}$ is correct, but we should check for $\geq$

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about value >= 2 ** 63 || value < -(2 ** 63)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yea, forgot that we take Math.abs

@cieplypolar
Copy link
Collaborator

According to your question, I believe if we take bigint as the argument we can handle the whole range of abstractInt. So imo we shouldn't cast numbers between $2^{53}$ and $2^{63} - 1$ as floats.

@aleksanderkatan aleksanderkatan merged commit 653d78e into main Oct 17, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants